//
//  GlShopModel.swift
//
//  Created by eme on 2016/12/1
//  Copyright (c) . All rights reserved.
//

import Foundation
import SwiftyJSON
import RealmSwift
import ModelProtocol

public class GlShopModel: Object, ModelProtocol {
    
    // MARK: Declaration for string constants to be used to decode and also serialize.
    internal let kGlShopSpcontactKey: String = "spcontact"
    internal let kGlShopAgprovincenameKey: String = "agprovincename"
    internal let kGlShopSplicenseKey: String = "splicense"
    internal let kGlShopSpstateKey: String = "spstate"
    internal let kGlShopSpcompanyKey: String = "spcompany"
    internal let kGlShopSpareacodeKey: String = "spareacode"
    internal let kGlShopSpcodeKey: String = "spcode"
    internal let kGlShopAginvitecodeKey: String = "aginvitecode"
    internal let kGlShopSpidKey: String = "spid"
    internal let kGlShopSpinvoiceKey: String = "spinvoice"
    internal let kGlShopAgareanameKey: String = "agareaname"
    internal let kGlShopAgprovincecodeKey: String = "agprovincecode"
    internal let kGlShopUseridKey: String = "userid"
    internal let kGlShopSpregdateKey: String = "spregdate"
    internal let kGlShopSpmobileKey: String = "spmobile"
    internal let kGlShopPasswordKey: String = "password"
    internal let kGlShopSpareanameKey: String = "spareaname"
    internal let kGlShopSpnameKey: String = "spname"
    internal let kGlShopSplicenseurlKey: String = "splicenseurl"
    internal let kGlShopAgareacodeKey: String = "agareacode"
    
    
    // MARK: 属性
    public dynamic var spcontact: String!
    public dynamic var agprovincename: String!
    public dynamic var splicense: String!
    public dynamic var spstate: String!
    public dynamic var spcompany: String!
    public dynamic var spareacode: String!
    public dynamic var spcode: String!
    public dynamic var aginvitecode: String!
    public dynamic var spid: String!
    public dynamic var spinvoice: String!
    public dynamic var agareaname: String!
    public dynamic var agprovincecode: String!
    public dynamic var userid:Int = 0
    public dynamic var spregdate: String!
    public dynamic var spmobile: String!
    public dynamic var password: String!
    public dynamic var spareaname: String!
    public dynamic var spname: String!
    public dynamic var splicenseurl: String!
    public dynamic var agareacode: String!
    public dynamic var auditremark: String!
    public dynamic var spaddress: String!
    
    ///状态:1-正常(审核通过) 2-代理审核 3-入驻审核 4-冻洁 5-代理审核失败 6-入驻审核失败
    public var showSpstate :String!{
        get {
            let dict = ["1":"审核通过","2":"审核中","3":"审核中","4":"已冻洁","5":"审核未通过","6":"审核未通过"]
            return dict[self.spstate] ?? ""
        }
    }
    public override static func primaryKey() -> String? {
        return "spid"
    }
    // MARK: 实现MikerSwiftJSONAble 协议， 解析json数据
    public required  convenience init?(json: JSON) {
        self.init()
        auditremark = json["auditremark"].stringValue
        spcontact = json[kGlShopSpcontactKey].stringValue
        agprovincename = json[kGlShopAgprovincenameKey].stringValue
        splicense = json[kGlShopSplicenseKey].stringValue
        spstate = json[kGlShopSpstateKey].stringValue
        spcompany = json[kGlShopSpcompanyKey].stringValue
        spareacode = json[kGlShopSpareacodeKey].stringValue
        spcode = json[kGlShopSpcodeKey].stringValue
        aginvitecode = json[kGlShopAginvitecodeKey].stringValue
        spid = json[kGlShopSpidKey].stringValue
        spinvoice = json[kGlShopSpinvoiceKey].stringValue
        agareaname = json[kGlShopAgareanameKey].stringValue
        agprovincecode = json[kGlShopAgprovincecodeKey].stringValue
        userid = json[kGlShopUseridKey].intValue
        spregdate = json[kGlShopSpregdateKey].stringValue
        spmobile = json[kGlShopSpmobileKey].stringValue
        password = json[kGlShopPasswordKey].stringValue
        spareaname = json[kGlShopSpareanameKey].stringValue
        spname = json[kGlShopSpnameKey].stringValue
        splicenseurl = json[kGlShopSplicenseurlKey].stringValue
        agareacode = json[kGlShopAgareacodeKey].stringValue
        spaddress = json["spaddress"].stringValue
        
    }
    
    
    /**
     Generates description of the object in the form of a NSDictionary.
     - returns: A Key value pair containing all valid values in the object.
     */
    public func dictionaryRepresentation() -> [String : AnyObject ] {
        
        var dictionary: [String : AnyObject ] = [ : ]
        if auditremark != nil {
            dictionary.updateValue(auditremark!  as AnyObject , forKey: "auditremark")
        }
        if spcontact != nil {
            dictionary.updateValue(spcontact!  as AnyObject , forKey: kGlShopSpcontactKey)
        }
        if agprovincename != nil {
            dictionary.updateValue(agprovincename!  as AnyObject , forKey: kGlShopAgprovincenameKey)
        }
        if splicense != nil {
            dictionary.updateValue(splicense!  as AnyObject , forKey: kGlShopSplicenseKey)
        }
        if spstate != nil {
            dictionary.updateValue(spstate!  as AnyObject , forKey: kGlShopSpstateKey)
        }
        if spcompany != nil {
            dictionary.updateValue(spcompany!  as AnyObject , forKey: kGlShopSpcompanyKey)
        }
        if spareacode != nil {
            dictionary.updateValue(spareacode!  as AnyObject , forKey: kGlShopSpareacodeKey)
        }
        if spcode != nil {
            dictionary.updateValue(spcode!  as AnyObject , forKey: kGlShopSpcodeKey)
        }
        if aginvitecode != nil {
            dictionary.updateValue(aginvitecode!  as AnyObject , forKey: kGlShopAginvitecodeKey)
        }
        if spid != nil {
            dictionary.updateValue(spid!  as AnyObject , forKey: kGlShopSpidKey)
        }
        if spinvoice != nil {
            dictionary.updateValue(spinvoice!  as AnyObject , forKey: kGlShopSpinvoiceKey)
        }
        if agareaname != nil {
            dictionary.updateValue(agareaname!  as AnyObject , forKey: kGlShopAgareanameKey)
        }
        if agprovincecode != nil {
            dictionary.updateValue(agprovincecode!  as AnyObject , forKey: kGlShopAgprovincecodeKey)
        }
        dictionary.updateValue(userid as AnyObject, forKey: kGlShopUseridKey)
        if spregdate != nil {
            dictionary.updateValue(spregdate!  as AnyObject , forKey: kGlShopSpregdateKey)
        }
        if spmobile != nil {
            dictionary.updateValue(spmobile!  as AnyObject , forKey: kGlShopSpmobileKey)
        }
        if password != nil {
            dictionary.updateValue(password!  as AnyObject , forKey: kGlShopPasswordKey)
        }
        if spareaname != nil {
            dictionary.updateValue(spareaname!  as AnyObject , forKey: kGlShopSpareanameKey)
        }
        if spname != nil {
            dictionary.updateValue(spname!  as AnyObject , forKey: kGlShopSpnameKey)
        }
        if splicenseurl != nil {
            dictionary.updateValue(splicenseurl!  as AnyObject , forKey: kGlShopSplicenseurlKey)
        }
        if agareacode != nil {
            dictionary.updateValue(agareacode!  as AnyObject , forKey: kGlShopAgareacodeKey)
        }
        
        return dictionary
    }
    
    
}
